<html>
<head>
<title>管理系统</title>
<meta http-equiv=Content-Type content=text/html;charset=utf-8>
<#include "../inc/commonJs.html">
<script language="JavaScript">
	var grid;
	$(function() {
		//分类管理表格  
		grid = $('#votegrid').datagrid({
	    url:'listVote.do',  
	    loadMsg:'数据加载中请稍后……',  
	    pagination: true,  
	    rownumbers: true, 
        striped: true,  
        singleSelect : true,  
        pageSize: [${syscfg.pageSize!10}],
        pageList: [${syscfg.pageList!10}],
        columns:[[  
             {field:'id',title: 'ID',align: 'center',width: '50'},  
             {field:'title',title: '主题',align: 'center',width: '250'},
             {field:'selectclass',title: '类型',align: 'center',width: '150',
             	formatter:function(value,rowdata,index){
					if(value ==1){
						return "多选";
					}else{
						return "单选";
					}
             	}
             },
             {field:'dt',title: '时间',align: 'center',width: '250'},
             {field:'ischecked',title: '操作',align: 'center',width: '200',
             	formatter: function(value,rowdata,index){
             		var str = '';
					if(value ==0){
						str += '<a id="btnadd" class="l-btn l-btn-plain" href="javascript:void(0)"><span class="l-btn-left"><span class="l-btn-text icon-no l-btn-icon-left" onclick="cancleVote('+rowdata.id+','+rowdata.ischecked+')">开始投票</span></span></a>';
					}else{
						str += '<a id="btnadd" class="l-btn l-btn-plain" href="javascript:void(0)"><span class="l-btn-left"><span class="l-btn-text icon-ok l-btn-icon-left" onclick="cancleVote('+rowdata.id+','+rowdata.ischecked+')">取消投票</span></span></a>';
					}
					return str;
				}
             }]],
             toolbar : [btn_add, btn_edit, btn_del,"-"]
     });
  })
  //新增用户
	function doAdd() {
		var url = '${request.contextPath}/xadmin/added/voteWindow.do';
		top.modalwindow(url, grid,{ width:500,height:400,title:'新增投票信息'});
	}	
	//工具栏修改用户
	function doEdit() {
		var selected = grid.datagrid('getSelected');
		if(!selected){
			top.noselectedalert();
			return;
		}
		var url = '${request.contextPath}/xadmin/added/voteWindow.do?id='+selected.id;
		top.modalwindow(url, grid,{width:500, height:400,title:'修改投票信息'});
	}
	//工具栏删除用户
	function doDel(){
		var selected = grid.datagrid('getSelected');
		if(!selected){
			top.noselectedalert();
			return;
		}
		$.messager.confirm('系统提示', '<br>&nbsp;&nbsp;&nbsp;&nbsp;你确定要删除该信息?', function(r) {
			if (r) {
				$.post("delVote.do", { "id": selected.id},
				   function(data){
				   	grid.datagrid('reload'); 
				   	top.messagershow(data);
				});
			}
		});
	}
	function cancleVote(id,result){
		if(result==0){
			result = 1;
		}else{
			result = 0;
		}
		$.post("checkVote.do", { "id": id,"result" : result},
		   	function(data){
		   		grid.datagrid('reload'); 
		   		top.messagershow(data);
		});
	}
</script>
</head>
<body>
	<table id="votegrid" data-options="fit:true,border:false"></table>
</body>
</html>